package com.shketai.service;

import java.util.List;

import com.shketai.dao.ClassinfoDao;
import com.shketai.entity.Classinfo;
import com.shketai.entity.Info;
import com.shketai.entity.PageBean;

public class ClassinfoService {

	private ClassinfoDao classinfoDao;

	public void setClassinfoDao(ClassinfoDao classinfoDao) {
		this.classinfoDao = classinfoDao;
	}

	public int add(Classinfo classinfo,int subject_id){
		int result = classinfoDao.add(classinfo, subject_id);
		return result;		
	}
	
	public int delete(Classinfo classinfo){
		int result = classinfoDao.delete(classinfo);
		return result;	
	}
	
	public int update(Classinfo classinfo){
		int result = classinfoDao.update(classinfo);
		return result;
	}
	
	public void selectClassroom(Classinfo classinfo){
		//根据calssinfo的id，查询要排班的班级
		Classinfo ci = classinfoDao.findById(classinfo.getId());
		//这个班级之前没有安排教室，此处给他安排一个教室时间段
		ci.setClassroominfo(classinfo.getClassroominfo());
		//利用快照机制更新
	}
	
	
	/**
	 * 查询出符合年龄的班级
	 * @param subjectId
	 * @param age
	 * @return
	 * @throws Exception 
	 */
	public PageBean<Classinfo> findBySubjectAndAge(int major_id,int stu_id,int page) throws Exception{
		PageBean<Classinfo> pb = new PageBean<Classinfo>();
		List<Classinfo> list = classinfoDao.findBySubjectAndAge(major_id, stu_id, page);
		pb.setDatas(list);
		int total = classinfoDao.findCount1(major_id, stu_id);
		pb.setTotal(total);
		return pb;
	}
	
	public List<Classinfo> findBySubjectAndAges(int subject_id,int stu_id) throws Exception{
		
		List<Classinfo> list = classinfoDao.findBySubjectAndAges(subject_id, stu_id);
		return list;
	}
	public int selectSubject(int stu_id,int classinfo_id){
		//选课之前，先判断时间段是否有冲突
		boolean flag = classinfoDao.checkPeriod(stu_id,classinfo_id);
		if(flag){
			//冲突了
			return 0;
		}else{
			 classinfoDao.selectSubject(stu_id, classinfo_id);
			
			 return 1;
		}
	}
    public int getNum(int classinfo_id){
    	return classinfoDao.getNum(classinfo_id);
    }
	public int findflag(int classinfo_id){
		int result = classinfoDao.findflag(classinfo_id);
		return result;
	}
	public int findInterview_info(int stu_id){
		int result = classinfoDao.findInterview_info(stu_id);
		return result;
	}
	
	/*public void quitSubject(int id) {
		classinfoDao.quitSubject(id);
	}*/

		public PageBean<Classinfo> findAll(int page) {
			PageBean<Classinfo> pb = new PageBean<Classinfo>();
		    List<Classinfo> list =classinfoDao.findAll(page);
		    pb.setDatas(list);
			int total = classinfoDao.findCount();
			pb.setTotal(total);
			return pb;
	}
	
		public List<Classinfo> findAll1() {
			//PageBean<Classinfo> pb = new PageBean<Classinfo>();
		    List<Classinfo> list =classinfoDao.findAll1();
		   /* pb.setDatas(list);
			int total = classinfoDao.findCount();
			pb.setTotal(total);*/
			return list;
	}
		public int findRQ(int classinfo_id) {
			int result = classinfoDao.findRQ(classinfo_id);
			return result;
		}
	public List<Classinfo> queryByUsername(String classname){
		return classinfoDao.queryByUsername(classname);
	}
	
	public List<Classinfo> findRoom(int classroom_id){
	return classinfoDao.findRoom(classroom_id);
	}
}
